package com.ruoyi.place.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.place.domain.bo.PlaceKfjzzxBo;
import com.ruoyi.place.domain.vo.PlaceKfjzzxVo;
import com.ruoyi.place.service.IPlaceKfjzzxService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.Arrays;
import java.util.List;

/**
 * 康复救助中心
 *
 * @author xiaohao
 * @date 2023-01-19
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/place/kfjzzx")
public class PlaceKfjzzxController extends BaseController {

    private final IPlaceKfjzzxService iPlaceKfjzzxService;

    /**
     * 查询康复救助中心列表
     */
    @SaCheckPermission("place:kfjzzx:list")
    @GetMapping("/list")
    public TableDataInfo<PlaceKfjzzxVo> list(PlaceKfjzzxBo bo, PageQuery pageQuery) {
        return iPlaceKfjzzxService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出康复救助中心列表
     */
    @SaCheckPermission("place:kfjzzx:export")
    @Log(title = "康复救助中心", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(PlaceKfjzzxBo bo, HttpServletResponse response) {
        List<PlaceKfjzzxVo> list = iPlaceKfjzzxService.queryList(bo);
        ExcelUtil.exportExcel(list, "康复救助中心", PlaceKfjzzxVo.class, response);
    }

    @GetMapping("/query")
    public R<List<PlaceKfjzzxVo>> getList() {
        return R.ok(iPlaceKfjzzxService.queryList(new PlaceKfjzzxBo()));
    }

    /**
     * 获取康复救助中心详细信息
     *
     * @param kfjzzxId 主键
     */
    @SaCheckPermission("place:kfjzzx:query")
    @GetMapping("/{kfjzzxId}")
    public R<PlaceKfjzzxVo> getInfo(@NotNull(message = "主键不能为空")
                                    @PathVariable Long kfjzzxId) {
        return R.ok(iPlaceKfjzzxService.queryById(kfjzzxId));
    }

    /**
     * 新增康复救助中心
     */
    @SaCheckPermission("place:kfjzzx:add")
    @Log(title = "康复救助中心", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody PlaceKfjzzxBo bo) {
        return toAjax(iPlaceKfjzzxService.insertByBo(bo));
    }

    /**
     * 修改康复救助中心
     */
    @SaCheckPermission("place:kfjzzx:edit")
    @Log(title = "康复救助中心", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody PlaceKfjzzxBo bo) {
        return toAjax(iPlaceKfjzzxService.updateByBo(bo));
    }

    /**
     * 删除康复救助中心
     *
     * @param kfjzzxIds 主键串
     */
    @SaCheckPermission("place:kfjzzx:remove")
    @Log(title = "康复救助中心", businessType = BusinessType.DELETE)
    @DeleteMapping("/{kfjzzxIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] kfjzzxIds) {
        return toAjax(iPlaceKfjzzxService.deleteWithValidByIds(Arrays.asList(kfjzzxIds), true));
    }
}
